<%@ page language="java" pageEncoding="UTF-8" import="com.chinapost.util.AuthUtil"%>
<%@ taglib prefix="my" uri="/WEB-INF/tlds/permission.tld" %>
<%
	AuthUtil authUtil = new AuthUtil(session);
%>
<script type="text/javascript">
	var wd_datagrid;
	$(function() {
		wd_datagrid = $('#wd_manager_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/wdAction!datagrid.action',
			pagination : true,
			pageSize : 20,
			pageList : [  10, 20, 30, 40, 50 ],
			border : false,
			fit : true,
			fitColumns : true,
			idField : 'cjgh',
			sortName : 'cjgh',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : true,
			columns : [ [{
				checkbox : true  
			}, {
				title : '所属单位',
				field : 'deptname',
				align : "center",
				width : 140
			}, {
				title : '网点机构号',
				field : 'cjgh',
				width : 100,
				align : "center"
			}, {
				title : '网点名称',
				field : 'cname',
				align : "center",
				width : 140
			},  {
				field : 'action',
				title : '操作',
				width : 100,
				align : 'center',
				formatter : function(value, row, index) {
					var str='';
                	<%if (authUtil.isAuth("/wdAction!wdEdit.action")){%>
                	str += sy.fs('<img onclick="wdEdit(\'{0}\');" src="{1}" style="cursor: pointer;" title="修改"/>&nbsp;',row.cjgh,'${pageContext.request.contextPath}/css/themes/icons/pencil.png');
                	<%}%>
                	<%if (authUtil.isAuth("/wdAction!delete.action")){%>
                	str += sy.fs('<img onclick="wdDelete(\'{0}\');" src="{1}" style="cursor: pointer;" title="删除"/>&nbsp;',row.cjgh,'${pageContext.request.contextPath}/css/themes/icons/no.png');
                	<%}%>
                	return str;
				}
			} ] ],
			toolbar : '#wd_toolbar'
		});
		 $('#wd_manager_dept').combotree({
				lines:true,
				url:'deptAction!do_combotree.action',
				panelHeight:200,
				required:true,
				editable:false,
				idField:'id',
				textField:'text',
				parentField:'pid',
				//禁止选择叶子节点
				 onBeforeSelect: function(node) {
			            if ($(this).tree('isLeaf', node.target)) {
			                return false;
			            }
			        },
			        onClick: function(node) {
			            if ($(this).tree('isLeaf', node.target)) {
			                $('#wd_manager_dept').combo('showPanel');
			            }
			        }
			}); 
		$('#wd_manager_dept').combotree('setValue','${sessionInfo.deptid}');
	});

	function wdEdit(cid) {
		if (cid != undefined) {
			$('#wd_manager_datagrid').datagrid('unselectAll');
			$('#wd_manager_datagrid').datagrid('selectRecord', cid);
		}
		var rows = $('#wd_manager_datagrid').datagrid('getSelected');
		var p = parent.sy.dialog({
			title : '修改网点',
			iconCls : 'icon-edit',
			href : '${pageContext.request.contextPath}/wdAction!wdEdit.action',
			width : 380,
			height : 220,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/wdAction!edit.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								wd_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				var f = p.find('form');
				f.form('load', rows);
				f.find('input[name="cname"]').select();
			}
		});
	};
	function wdAppend() {
		var p = parent.sy.dialog({
			title : '添加网点(只添加可核算任务的网点机构)',
			iconCls : 'icon-append',
			href : '${pageContext.request.contextPath}/wdAction!wdAdd.action',
			width : 380,
			height : 220,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/wdAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								wd_datagrid.datagrid('reload');
								f.find('input[name="cjgh"]').val('').focus();
								f.find('input[name="cname"]').val('');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				p.find('form input[name="cjgh"]').focus();
			}
		});
	}
	function wdRemove() {
		var rows = wd_datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '是否删除当前所选记录？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].cjgh);
					}
					$.ajax({
						url : '${pageContext.request.contextPath}/wdAction!delete.action',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							wd_datagrid.datagrid('load');
							$('#wd_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
							parent.sy.messagerShow({
								title : '提示',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请选择要删除的记录！', 'error');
		}
	};

	function wdDelete(cid) {
		$('#wd_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('#wd_manager_datagrid').datagrid('checkRow', $('#wd_manager_datagrid').datagrid('getRowIndex', cid));
		wdRemove();
	}

	function _searchWd() {
		wd_datagrid.datagrid('load', sy.serializeObject($('#wd_search_form')));
		wd_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
	function _cleanSearchWd() {
		$('#wd_search_form  input[name="cname"]').val('');
		$('#wd_search_form  input[name="cjgh"]').val('');
		$('#wd_manager_dept').combotree('setValue','${sessionInfo.deptid}');
		wd_datagrid.datagrid('load', sy.serializeObject($('#wd_search_form')));
		wd_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
</script>




<div class="easyui-layout" data-options="fit:true" style="overflow: hidden;">
	<div data-options="region:'north',title:'查询网点',iconCls:'icon-search'" style="height: 80px;padding:5px;overflow: hidden;">
		<div style="padding:5px">
			<form method="post" id="wd_search_form" style="display:inline">
			<span>所属机构：</span>
			<input id="wd_manager_dept"   name="deptid"  style="width:180px"/>&nbsp;&nbsp;
				<span> 网点名称：</span> <input type='text' name='cname' />&nbsp;&nbsp;
				<span> 机构号：</span> <input type='text' name='cjgh' />&nbsp;
			</form>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="_searchWd();">查询</a>&nbsp; <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onClick="_cleanSearchWd();">清空</a>
		</div>
	</div>
	<div data-options="region:'center',title:'网点列表',border:true,iconCls:'icon-application'" style="overflow: hidden;">
		<table id="wd_manager_datagrid"></table>
	</div>
</div>
<div id="wd_toolbar" style="display: none;" >
<table  class="toolbar" >
	<tr>
		<my:per url="/wdAction!wdAdd.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-append',plain:true" onclick="wdAppend();">新增</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/wdAction!delete.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-delete',plain:true" onclick="wdRemove()">批量删除</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
	</tr>
</table>
</div>
